<?php
// +----------------------------------------------------------------------
// | Fanwe 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.fanwe.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 云淡风轻(97139915@qq.com)
// +----------------------------------------------------------------------

// 日志列表
class LogAction extends CommonAction{
	public function index()
	{
		//列表过滤器，生成查询Map对象
		$map = $this->_search ();		
		if (method_exists ( $this, '_filter' )) {
			$this->_filter ( $map );
		}
		
		if(!empty($_REQUEST['begin_time'])){
			$map['log_time'] = array("egt",localStrToTime($_REQUEST['begin_time']));
			$this->assign("begin_time",toDate(localStrToTime($_REQUEST['begin_time']),"Y-m-d H:i"));
		}
		
		if(!empty($_REQUEST['end_time'])){
			$map['log_time'] = array("egt",localStrToTime($_REQUEST['end_time']));
			$this->assign("end_time",toDate(localStrToTime($_REQUEST['end_time']),"Y-m-d H:i"));
		}
		
		if(!empty($_REQUEST['begin_time']) && !empty($_REQUEST['end_time']))
		{
			$map['log_time'] = array(array("egt",localStrToTime($_REQUEST['begin_time'])),array("elt",localStrToTime($_REQUEST['end_time'])),'and');
			$this->assign("begin_time",toDate(localStrToTime($_REQUEST['begin_time']),"Y-m-d H:i"));
			$this->assign("end_time",toDate(localStrToTime($_REQUEST['end_time']),"Y-m-d H:i"));
		}
		
		if(!empty($_REQUEST['operate_msg'])){
			$map['log_msg'] = array("like",'%'.trim($_REQUEST['operate_msg']).'%');
			$this->assign("operate_msg",trim($_REQUEST['operate_msg']));
		}
		
		
		$name=$this->getActionName();
		$model = D ($name);
		if (! empty ( $model )) {
			$this->_list ( $model, $map );
		}
		$this->display ();
		return;
	}
	
	public function goodsLog()
	{
		//列表过滤器，生成查询Map对象
		$map = $this->_search ();
		$map['log_module'] = array('in',array('Goods','GoodsCate'));
		if (method_exists ( $this, '_filter' )) {
			$this->_filter ( $map );
		}
		$name=$this->getActionName();
		$model = D ($name);
		if (! empty ( $model )) {
			$this->_list ( $model, $map );
		}
		$this->display ();
		return;
	}
	
	public function articleLog()
	{
		//列表过滤器，生成查询Map对象
		$map = $this->_search ();
		$map['log_module'] = array('in',array('Article','ArticleCate'));
		if (method_exists ( $this, '_filter' )) {
			$this->_filter ( $map );
		}
		$name=$this->getActionName();
		$model = D ($name);
		if (! empty ( $model )) {
			$this->_list ( $model, $map );
		}
		$this->display ();
		return;
	}
	
	public function orderLog()
	{
		//列表过滤器，生成查询Map对象
		$map = $this->_search ();
		$map['log_module'] = array('in',array('Order','OrderGoods'));
		if (method_exists ( $this, '_filter' )) {
			$this->_filter ( $map );
		}
		$name=$this->getActionName();
		$model = D ($name);
		if (! empty ( $model )) {
			$this->_list ( $model, $map );
		}
		$this->display ();
		return;
	}
	
	public function clearSysLog()
	{
		$month=intval($_REQUEST['month']) == 0 ? 6 : intval($_REQUEST['month']);
		$name=$this->getActionName();
		$model = D ($name);
		$model->where("log_time < '".(gmtTime() - $month*31*24*3600)."'")->delete();
		$this->saveLog(1,0,"清除了后台日志");
		return $this->success(L('CLEAR_SUCCESS'),true);
	}
	
}
?>